local jutu = fk.CreateSkill{
    name = "wk_heg__jutu",
}

Fk:loadTranslationTable{
  ["wk_heg__jutu"] = "据土",
  [":wk_heg__jutu"] = "①出牌阶段结束时，你可以将一张方块牌当【乐不思蜀】对自己使用，然后回复1点体力或摸两张牌；②若你的判定区内有牌，其他角色计算与你的距离+1。",

  ["#wk_heg__jutu-choose"] = "据土：你可以将一张方块牌当【乐不思蜀】对自己使用",
  ["wk_heg__jutu_drawcard"] = "摸两张牌",
  ["wk_heg__jutu_recover"] = "回复1点体力",

  ["$wk_heg__jutu1"] = "",
  ["$wk_heg__jutu2"] = "",
}

local H = require "packages/ol_hegemony/util"
local HG = require "packages/new_heg_diy_my/util"

jutu:addEffect(fk.EventPhaseEnd,{
    anim_type = "special",
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(jutu.name) and player == target and target.phase == Player.Play and not player:hasDelayedTrick("indulgence")
    end,
    on_cost = function(self, event, target, player, data)
      local room = player.room
      local cards = room:askToCards(player,{
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = jutu.name,
        pattern = ".|.|diamond|hand,equip|.|.",
        prompt = "#wk_heg__jutu-choose",
        cancelable = true,
      })
      if #cards > 0 then
        event:setCostData(self, {cards = cards[1]})
        return true
      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local cards = event:getCostData(self).cards
      local card = Fk:getCardById(cards)
      if player.dead then return end
      room:useVirtualCard("indulgence", card, player, player, jutu.name)
      local choices = {"wk_heg__jutu_drawcard"}
      if player.hp < player.maxHp then
        table.insert(choices, "wk_heg__jutu_recover")
      end
      local choice = room:askToChoice(player, {choices = choices, skill_name = jutu.name})
      if choice == "wk_heg__jutu_drawcard" then
        player:drawCards(2, jutu.name)
      else
        room:recover({
           who = player,
           num = 1,
           recoverBy = player,
           skillName = jutu.name,
          })
       end
    end,
})

jutu:addEffect("distance", {
  correct_func = function(self, from, to)
    if to:hasSkill(jutu.name) and to:hasShownSkill(jutu.name) and #to:getCardIds("j") > 0 then
      return 1
    end
  end,
})


return jutu